package main

import (
	"fmt"
	"sync"
	"sync/atomic"
)

var (
	x    int64
	wg   sync.WaitGroup
	lock sync.Mutex
)

func main() {
	for i := 0; i < 10000; i++ {
		wg.Add(1)
		go add()
	}
	wg.Wait()
	fmt.Println(x)
}

func add() {
	//lock.Lock()
	atomic.AddInt64(&x, 1)
	//lock.Unlock()
	wg.Done()
}
